GtkWidget *inner_box;
GtkWidget *test_widget;
GtkWidget *label;
- GdkRGBA color;
outer_box = gtk_event_box_new ();
- gdk_rgba_parse (&color, "black");
- gtk_widget_override_background_color (outer_box, 0, &color);
+ gtk_style_context_add_class (gtk_widget_get_style_context (outer_box), "black-bg");
inner_box = gtk_event_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (inner_box), 5);
- gdk_rgba_parse (&color, "blue");
- gtk_widget_override_background_color (inner_box, 0, &color);
+ gtk_style_context_add_class (gtk_widget_get_style_context (inner_box), "blue-bg");
gtk_container_add (GTK_CONTAINER (outer_box), inner_box);
test_widget = gtk_event_box_new ();
- gdk_rgba_parse (&color, "red");
- gtk_widget_override_background_color (test_widget, 0, &color);
+ gtk_style_context_add_class (gtk_widget_get_style_context (test_widget), "red-bg");
gtk_container_add (GTK_CONTAINER (inner_box), test_widget);
int
main (int argc, char *argv[])
{
+ GtkCssProvider *provider;
+
gtk_init (&argc, &argv);
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (provider,
+ ".black-bg { background-color: black; }"
+ ".red-bg { background-color: red; }"
+ ".blue-bg { background-color: blue; }", -1, NULL);
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (provider);
+
if (g_getenv ("RTL"))
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
gtk_image_set_pixel_size (GTK_IMAGE (image), size);
}
+static void
+set_font_size (GtkWidget *widget, gint size)
+{
+ const gchar *class[3] = { "small-font", "medium-font", "large-font" };
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (widget), class[size]);
+}
+
int
main (int argc,
char **argv)
{
GtkWidget *window, *label, *entry, *button, *grid, *notebook;
GtkWidget *vbox, *hbox, *grid_hbox, *spin, *spin2, *toggle, *combo, *image, *ebox;
- PangoFontDescription *font;
GtkAdjustment *adjustment;
int i, j;
+ GtkCssProvider *provider;
gtk_init (&argc, &argv);
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (provider,
+ ".small-font { font-size: 5px; }"
+ ".medium-font { font-size: 10px; }"
+ ".large-font { font-size: 15px; }", -1, NULL);
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (provider);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);
for (i = 0; i < 3; i++) {
label = gtk_label_new ("│XYyj,Ö...");
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (label, font);
+ set_font_size (label, i);
gtk_widget_set_valign (label, aligns[j]);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "│XYyj,Ö...");
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (entry, font);
+ set_font_size (entry, i);
gtk_widget_set_valign (entry, aligns[j]);
{
button = gtk_button_new_with_label ("│Xyj,Ö");
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (button, font);
+ set_font_size (button, i);
if (j == 0)
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
gtk_image_new_from_icon_name ("face-sad", GTK_ICON_SIZE_BUTTON));
gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (button, font);
+ set_font_size (button, i);
if (j == 0)
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
{
label = gtk_label_new ("Xyjg,Ö.");
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (label, font);
+ set_font_size (label, i);
if (j != 0)
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
gtk_image_new_from_icon_name ("face-sad", GTK_ICON_SIZE_BUTTON));
gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (button, font);
+ set_font_size (button, i);
if (j != 0)
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
{
button = gtk_button_new_with_label ("│Xyj,Ö");
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (button, font);
+ set_font_size (button, i);
if (i != 0)
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
g_signal_connect (spin2, "value-changed", (GCallback)image_size_value_changed, image);
gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
- font = pango_font_description_new ();
- pango_font_description_set_size (font, 5*(i+1)* 1024);
- gtk_widget_override_font (button, font);
+ set_font_size (button, i);
gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);